package com.study.mybatisplus.controller.test;

import com.study.mybatisplus.entity.test.Account;
import com.study.mybatisplus.services.test.service.IAccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

/**
 * @Package: com.study.mybatisplus.entity.test.Account
 * @Description: <前端控制器>
 * @Author: Yi
 * @CreateDate: 2021-04-16
 * @UpdateUser: Yi
 * @UpdateDate: 2021-04-16
 * @UpdateRemark: <>
 * @Version: 1.0
 */
@RestController
@Api(tags = "Account-相关接口")
@RequestMapping(value = "Account")
public class AccountController {

    private static final Logger logger = LoggerFactory.getLogger(AccountController.class);

    @Autowired
    private IAccountService iIAccountService;

    @GetMapping("{id}")
    @ApiOperation(value = "获取某一实体")
    public Account getIAccountServiceDetails(@PathVariable Integer id) {
        return iIAccountService.getById(id);
    }

    @PostMapping
    @ApiOperation(value = "新增数据")
    public boolean saveIAccountService(@RequestBody Account dto) {
        return iIAccountService.save(dto);
    }

    @PutMapping("{id}")
    @ApiOperation(value = "修改数据")
    public boolean modifyIAccountService(@RequestBody Account dto, @PathVariable Integer id) {
        dto.setId(id);
        return iIAccountService.updateById(dto);
    }

    @DeleteMapping("batch")
    @ApiOperation(value = "批量删除数据")
    public boolean batchRemoveIAccountService(@RequestParam(value = "ids") List<Integer> ids) {
        return iIAccountService.removeByIds(ids);
    }

    @DeleteMapping("{id}")
    @ApiOperation(value = "删除数据")
    public boolean removeIAccountService(@PathVariable Integer id) {
        return iIAccountService.removeById(id);
    }
}